﻿//--------------------------------------------------------------------------------------------------------------------------------------------------------
// <copyright file="User.cs">
//     Copyright © 2010 Oli Francis
//     This source code is subject to the terms and conditions of the MIT license. A copy of the license can be found in the license.txt 
//     file at the root of this distribution. By using this source code in any fashion, you are agreeing to be bound by the terms of the MIT License. 
//     You must not remove this notice from the software.
// </copyright>
// <author>Oli</author>
//-------------------------------------------------------------------------------------------------------------------------------------------------------

namespace TeamBrain.Domain.Model
{
    using System;
    using System.ComponentModel.DataAnnotations;

    /// <summary>
    /// Class to model a user in the system
    /// </summary>
    public class User : Entity
    {
        /// <summary>
        /// Gets or sets the id of the user
        /// </summary>
        public virtual int Id { get; set; }

        /// <summary>
        /// Gets or sets the user's first name.
        /// </summary>
        [Required]
        public virtual string FirstName { get; set; }

        /// <summary>
        /// Gets or sets the user's last name.
        /// </summary>
        [Required]
        public virtual string LastName { get; set; }

        /// <summary>
        /// Gets or sets the email address.
        /// </summary>
        [Required]
        public virtual string EmailAddress { get; set; }

        /// <summary>
        /// Gets or sets the user's password. When retrieving a user object, this will not be available, as we only
        /// store a hashed version of the password
        /// </summary>
        [Required]
        [StringLength(20, MinimumLength = 5)]
        [RegularExpression(@"^(?=.*[0-9\!\£\$\%\^\&\*\(\)\-\=\|\?\@\#\;\:\<\>])(?!.*\s).*$", ErrorMessage = "Please enter at least one number or special character for better security")]
        public virtual string Password { get; set; }

        /// <summary>
        /// Gets or sets a unique salt to use in password hashing
        /// </summary>
        public virtual string Salt { get; set; }

        /// <summary>
        /// Gets or sets a hashed version of the user's password
        /// </summary>
        public virtual string PasswordHash { get; set; }

        /// <summary>
        /// Gets or sets a unique token that can be used to verify the account
        /// </summary>
        public virtual string ActivationToken { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether the user account is active.
        /// </summary>
        public virtual bool IsActive { get; set; }

        /// <summary>
        /// Gets or sets the number of recently failed sign in attempts.
        /// </summary>
        public virtual int FailedSignInAttemptCount { get; set; }

        /// <summary>
        /// Gets or sets the date and time of the last failed sign in attempt.
        /// </summary>
        public virtual DateTime? LastFailedSignInAttempt { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether this <see cref="User"/> is disabled.
        /// </summary>
        public virtual bool Disabled { get; set; }

        /// <summary>
        /// Gets or sets a unique token used to allow a user to reset their password
        /// </summary>
        public virtual string PasswordResetToken { get; set; }

        /// <summary>
        /// Gets or sets the time that the password reset token was issued
        /// </summary>
        public virtual DateTime? PasswordResetTokenTimeIssued { get; set; }
    }
}
